package logic

import (
	"context"
	"gorm.io/gorm"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户修改
func (l *UserUpdateLogic) UserUpdate(in *user.UserUpdateRequest) (*user.UserUpdateResponse, error) {
	// todo: add your logic here and delete this line
	updates := models.User{
		Model: gorm.Model{
			ID: uint(in.UserId),
		},
		Phone:    in.Phone,
		Password: in.Password,
	}
	models.DB.Updates(&updates)
	return &user.UserUpdateResponse{
		UserId:   int64(updates.ID),
		Phone:    updates.Phone,
		Password: updates.Password,
	}, nil
}
